﻿(function ($) {
    $.widget("lordjs.categoryWidget", {
        // default options
        options: {
            categoryId: null,
            category: []

            // callbacks
        },

        // the constructor
        _create: function () {
            this.element.addClass("category");

            // append fieldset
            var categoryHtml = "<fieldset class='category'>"
                + "<legend>" + this.options.category.category + "</legend>"
                + "<div>";

            var linkHtml = "<ul>";
            for (var i = 0; i < this.options.category.detail.length; i++) {
                linkHtml += "<li><a href='" + this.options.category.detail[i].link + "' target='_blank'>"
                    + this.options.category.detail[i].name + "</a></li>";
            }
            linkHtml += "</ul>";

            categoryHtml = categoryHtml + linkHtml + "</div></fieldset>";

            this.element.append(categoryHtml);

            // make the widget draggable
            this.element.draggable({ cursor: "crosshair", cursorAt: { top: 50, left: 50} });
        },

        // destructor
        destroy: function () {
            $.Widget.prototype.destroy.call(this);
        }
    });
})(jQuery)
